﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace hopchat
{
    
    class program
    {
        [STAThread]
        
        static void Main()
        {
            /*DonChat a = new DonChat("lala", "8", null, "lala");
            DonChat b = new DonChat("yeye", "4", null, "yeye");
            List<DonChat> c = new List<DonChat>();
            c.Add(a);
            c.Add(b);
            hop_chat d = new hop_chat(null, null, c);
            System.Windows.Forms.MessageBox.Show(d.xdcongthuc());*/
            List<hop_chat> test = loadINPUT();

            TapLuat testrule = new TapLuat(@"luat.xml");

            List<Luat> lstLuat = new List<Luat>();
            lstLuat.Add( new group21(testrule));
            lstLuat.Add(new group22(testrule));
            lstLuat.Add(new group23(testrule));
            lstLuat.Add(new group24(testrule));
            


            testrule.findInfo(test);

            bool flag = true;
            while (flag)
            {
                flag = false;
                foreach (Luat l in lstLuat)
                {

                    ruleReport rp = l.Xuly(test);
                    if (rp.success)
                    {
                        flag = true;
                        Console.WriteLine(rp.report+ "\n\n");
                        //System.Windows.Forms.MessageBox.Show(rp.report);
                    }
                }
            }

            foreach (hop_chat x in test)
                Console.WriteLine(x.ToString() + "\n");
                
        }

        static public List<hop_chat> loadINPUT()
        {
            List<hop_chat> rs = new List<hop_chat>();
            string path = @"de2.xml";
            XmlDocument de = new XmlDocument();
            de.Load(path);

            XmlNode Node = de.GetElementsByTagName("INPUT")[0];

            foreach (XmlNode x in Node.ChildNodes)
            {
                if (x.Name.ToLower() == "hopchat")
                {
                    XmlDocument hc = new XmlDocument();
                    XmlElement hcc = hc.CreateElement("hopchat");
                    hcc.InnerXml = x.InnerXml;
                    hc.AppendChild(hcc);

                    hop_chat hccc = new hop_chat(hc);
                    rs.Add(hccc);
                }
            }

            return rs;
        }
    }
}
